<?
if (isset($_POST['btnsubmit'])) {
    require("required/dbconnect.php");
    require("required/function.php");
    require("../required/share_function.php");
    require("../required/email.php");
    $status = $_POST['status'];
    $id = $_POST['id'];
    $is_redeem = $_POST['is_redeem'];
    $current_date = date('Y-m-d');
    if ($is_redeem == 0) {
        if ($status == 2) {


            $get_counter = mysql_query("select * from os_counter where counter_type='I' and counter_date='$current_date'");

            if (mysql_num_rows($get_counter) == 0) {
                mysql_query("insert into os_counter(counter_type,counter_date,total_count)values('I','$current_date','1')");
                $total_count = 1;
            } else {
                $total_count = mysql_result($get_counter, 0, "total_count") + 1;
                mysql_query("update os_counter set total_count='$total_count' where counter_date='$current_date' and counter_type='I'");
            }

            $invoice_number = "I" . leading_zeros($total_count, 3) . "" . date("dmY");

            $update = mysql_query("update os_bill_details set invoice_number='$invoice_number', status=$status,last_update_by_machant=now(),verified_date=now() where id=$id");

            $get_items = mysql_query("select a.id,a.item_id,a.quantity,b.pid from os_bill_items a inner join os_product_inventory b on a.item_id = b.id where a.bid=$id");

            while ($i = mysql_fetch_array($get_items, MYSQL_ASSOC)) {
                $item_id = $i['item_id'];
                $total_deduct = $i['quantity'];
                $pid = $i['pid'];
                updateInventory($item_id, $total_deduct, "deduct", $id, $pid);
            }
            email_invoice($id);
            $action = 2;
        } elseif ($status == 4) {
            $get_counter = mysql_query("select * from os_counter where counter_type='R' and counter_date='$current_date'");

            if (mysql_num_rows($get_counter) == 0) {
                mysql_query("insert into os_counter(counter_type,counter_date,total_count)values('R','$current_date','1')");
                $total_count = 1;
            } else {
                $total_count = mysql_result($get_counter, 0, "total_count") + 1;
                mysql_query("update os_counter set total_count='$total_count' where counter_date='$current_date' and counter_type='R'");
            }

            $receipt_number = "R" . leading_zeros($total_count, 3) . "" . date("dmY");

            $update = mysql_query("update os_bill_details set status=$status,receipt_number='$receipt_number',last_update_by_machant=now() where id=$id");
            email_receipt($id);
            $action = 3;
        } elseif ($status == 5) {
            $get_bill = mysql_query("select * from os_bill_details where id=$id");
            $b = mysql_fetch_array($get_bill, MYSQL_ASSOC);

            if ($b['courier_name'] == "" || $b['ref_no'] == "" || $b['eta'] == "") {
                $action = 10;
            } else {

                $get_counter = mysql_query("select * from os_counter where counter_type='C' and counter_date='$current_date'");

                if (mysql_num_rows($get_counter) == 0) {
                    mysql_query("insert into os_counter(counter_type,counter_date,total_count)values('C','$current_date','1')");
                    $total_count = 1;
                } else {
                    $total_count = mysql_result($get_counter, 0, "total_count") + 1;
                    mysql_query("update os_counter set total_count='$total_count' where counter_date='$current_date' and counter_type='C'");
                }

                $courier_number = "C" . leading_zeros($total_count, 3) . "" . date("dmY");

                $update = mysql_query("update os_bill_details set status=$status,last_update_by_machant=now(),courier_number='$courier_number' where id=$id");
                email_shipmentinfo($id);
                $action = 5;
            }
        } elseif ($status == 8) {
            header("Location:order_delete.php?id=$id");
        } elseif ($status == 9) {

            $update_status = mysql_query("update os_bill_details set sale_close=1,status=9 where id=$id") or die(mysql_error());

            $action = 9;
        } else {
            $update = mysql_query("update os_bill_details set status=$status,last_update_by_machant=now() where id=$id");
            $action = 1;
        }
    } else {
        $update = mysql_query("update os_bill_details set status=$status,last_update_by_machant=now() where id=$id");

        if ($status == 2) {
            $get_items = mysql_query("select a.id,a.item_id,a.quantity,b.pid from os_bill_items a inner join os_product_inventory b on a.item_id = b.id where a.bid=$id");
            $i = mysql_fetch_array($get_items, MYSQL_ASSOC);
            $item_id = $i['item_id'];
            $total_deduct = $i['quantity'];
            $pid = $i['pid'];
            updateInventory($item_id, $total_deduct, "deduct", $id, $pid);
        }


        $action = 1;
    }

    header("Location:order_viewfull.php?id=$id&action=$action");
}

if (isset($_POST['btnsendemail'])) {
    require("required/dbconnect.php");
    require("required/function.php");
    require("../required/share_function.php");
    require("../required/email.php");
    $status = $_POST['status'];
    $id = $_POST['id'];
    $update_allow=1;

    if ($status == 2) {

        email_invoice($id);
        $action = 2;
    } elseif ($status == 4) {
        email_receipt($id);
        $action = 3;
    } elseif ($status == 5) {
        $get_bill = mysql_query("select * from os_bill_details where id=$id");
        $b = mysql_fetch_array($get_bill, MYSQL_ASSOC);

        if ($b['courier_name'] == "" || $b['ref_no'] == "" || $b['eta'] == "") {
            $action = 10;
        } else {
            email_shipmentinfo($id);
            $action = 5;
        }
    }

    header("Location:order_viewfull.php?id=$id&action=$action");
}


if (isset($_POST['btnupdate'])) {
    require("required/dbconnect.php");

    $id = $_POST['id'];
    $transport_fees = $_POST['transport_fees'];
    $discount = $_POST['discount'];
    $update = mysql_query("update os_bill_details set transport_fees='$transport_fees',discount='$discount',last_update_by_machant=now() where id=$id");

    header("Location:order_viewfull.php?id=$id");
}

if (isset($_POST['btnupdate_courier'])) {
    require("required/dbconnect.php");

    $id = $_POST['id'];
    $courier_name = $_POST['courier_name'];
    $ref_no = $_POST['ref_no'];
    $eta = $_POST['eta'];
    $update = mysql_query("update os_bill_details set courier_name='$courier_name',ref_no='$ref_no',eta='$eta' where id=$id");

    header("Location:order_viewfull.php?id=$id&action=4");
}

if (isset($_POST['btnupdate_info'])) {
    require("required/dbconnect.php");

    $id = $_POST['id'];
    $name = $_POST['name'];
    $hpnumber = $_POST['contact_number'];

    $address1 = $_POST['address1'];
    $address2 = $_POST['address2'];
    $postcode = $_POST['postcode'];
    $country = $_POST['country'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $email = $_POST['email'];
    $message = mysql_escape_string($_POST['message']);
    //echo "update os_bill_details set receiver_name='$name',address1='$address1',address2='$address2',postcode='$postcode',city='$city',country='$country',state='$state,contact_number='$hpnumber',email='$email',message='$message' where id=$id";
    $update = mysql_query("update os_bill_details set receiver_name='$name',address1='$address1',address2='$address2',postcode='$postcode',city='$city',country='$country',state='$state',contact_number='$hpnumber',email='$email',message='$message' where id=$id") or die(mysql_error());

    header("Location:order_viewfull.php?id=$id&action=6");
}

require("required/dbconnect.php");
require("required/function.php");
require("required/header.php");


$bid = mysql_real_escape_string($_GET['id']);

$get_bill = mysql_query("select * from os_bill_details where id='$bid'");
$b = mysql_fetch_array($get_bill, MYSQL_ASSOC);

$get_item = mysql_query("select * from os_bill_items where bid='$bid' and addon_for=0") or die("line 11" . mysql_error());

if (empty($_GET['action'])) {
    $action_msg = "";
} else {
    $action = $_GET['action'];

    if ($action == 1) {
        $action_msg = "<div class='dw_success'> Record Updated</div>";
    } elseif ($action == 2) {
        $action_msg = "<div class='dw_success'> An Invoice has been sent to buyer's email</div>";
    } elseif ($action == 3) {
        $action_msg = "<div class='dw_success'> A receipt to this payment has been sent to the buyer's email</div>";
    } elseif ($action == 4) {
        $action_msg = "<div class='dw_success'> Courier Info updated</div>";
    } elseif ($action == 5) {
        $action_msg = "<div class='dw_success'> Courier Info has been sent to buyer's email</div>";
    } elseif ($action == 6) {
        $action_msg = "<div class='dw_success'> Receiver Details Updated</div>";
    } elseif ($action == 9) {
        $action_msg = "<div class='dw_success'> Sale Closed</div>";
    } elseif ($action == 10) {
        $action_msg = "<div class='dw_failed'> Please complete courier information</div>";
    } else {
        $action_msg = "";
    }
}


$orange = $b['survey_1'] * 10;
$gray = 50 - ($b['survey_1'] * 10);
?>
<script language="JavaScript" type="text/javascript" src="../required/js/goAjax.js"></script>
<script>
    
    function changeState(countryId) {
		
        if(countryId!=""){
            changeContent('../required/js/ajax_place.php?country_id='+countryId+'&tag=state','divState')
        }
    }
    
    function formvalidate(frm1)
    {
		
        if(document.frm1.email.value=="")
        {
            alert("Please enter your email");
            document.frm1.email.focus();
            return false;
        }
        if (document.frm1.email.value!="")
        {
            var x = document.frm1.email.value;
            var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (filter.test(x)==false)
            { 
                alert('Please enter a valid email address');
                document.frm1.email.focus();
                return false;
            }
		
        }
        if(document.frm1.password.value=="")
        {
            alert("Please enter password");
            document.frm1.password.focus();
            return false;
        }
        if(document.frm1.password.value.length<6)
        {
            alert("password length must more than 6 characters");
            document.frm1.password.focus();
            return false;
        }
        if(document.frm1.password.value.indexOf(" ")>-1)
        {
            alert("spaces not allowed!");
            document.frm1.password.focus();
            return false;
        }
        if(document.frm1.cpassword.value=="")
        {
            alert("Please reenter your password");
            document.frm1.cpassword.focus();
            return false;
        }
        if(document.frm1.password.value!=document.frm1.cpassword.value)
        {
            alert("Password doesn't match, please check");
            document.frm1.cpassword.focus();
            return false;
        }
        if(document.frm1.name.value=="")
        {
            alert("Please enter your name");
            document.frm1.name.focus();
            return false;
        }
        if(document.frm1.address1.value=="")
        {
            alert("Please enter your address");
            document.frm1.address1.focus();
            return false;
        }
        if(document.frm1.email.value=="")
        {
            alert("Please enter your email");
            document.frm1.email.focus();
            return false;
        }
        if(document.frm1.email.value!="")
        {
            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            var address = document.frm1.email.value;
            if(reg.test(address) == false) {
                alert("Invalid email");
                document.frm1.email.focus();
                return false;
            }
        }
        if(document.frm1.verification_code.value=="")
        {
            alert("Please enter verification_code");
            document.frm1.verification_code.focus();
            return false;
        }
		
		
        return true;
    }
</script>
<table width="100%">

    <Td valign="top">
        <?
        if ($b['is_redeem'] == 1) {
            ?>
            <font class="title">Redemption Details</font>
            <?
        } else {
            ?>
            <font class="title">Order Details</font>
        <? } ?>
        <?= $action_msg ?>
        <table width="100%">

            <tr>
                <td width="100%">
                    <table width="100%">

                        <td width="20%" colspan="4">
                            <?
                            if ($b['is_redeem'] == 1) {
                                ?>
                                Status : <font color="#0066CC"><?= redeemstatus_eng($b['status']) ?></font>
                            <? } else { ?>
                                Order Status : <font color="#0066CC"><?= billstatus_eng($b['status']) ?></font>
                            <? } ?>
                        </td>

                        <tr>
                        <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm">
                            <td width="50%" valign="middle" align="left">
                                <?
                                if ($b['is_redeem'] == 1) {
                                    ?>
                                    Change status to 
                                    <select name="status" style="color:#0066CC;font-size:10px ">
                                        <?
                                        if ($b['status'] == 0) {
                                            ?>
                                            <option value="1">Confirmed</option>
                                            <?
                                        }

                                        if ($b['status'] == 1) {
                                            ?>
                                            <option value="2">Sent</option>
                                            <?
                                        }

                                        if ($b['status'] == 2) {
                                            ?>
                                            <option value="3">Received</option>	
                                        <? } ?>					
                                    </select>
                                    <input type="hidden" value="<?= $b['id'] ?>" name="id">
                                    <input type="hidden" value="1" name="is_redeem">
                                    <input type="submit" value="Go" class="button" name="btnsubmit">
                                    <?
                                } else {
                                    if ($b['status'] == 1 || $b['status'] == 3 || $b['status'] == 4 || $b['status'] == 10 || $b['status'] == -3 || $b['status'] == -4) {
                                        ?>


                                        Change status to 
                                        <select name="status" style="color:#0066CC;font-size:10px ">
                                            <?
                                            if ($b['status'] == 1) {
                                                ?>
                                                <option value="2">Order verified</option>
                                            <? } ?>
                                            <?
                                            if ($b['status'] == 3 || $b['status'] == 2 || $b['status'] == -3 || $b['status'] == -4) {
                                                ?>
                                                <option value="4">Merchant already received payment</option>
                                            <? } ?>

                                            <?
                                            if ($b['status'] == 4 || $b['status'] == 10 || $b['status'] == -4) {
                                                $update_allow=0;
                                                ?>
                                                <option value="5">Merchant shipped the goods</option>
                                            <? } ?>
                                        </select>
                                        <input type="hidden" value="<?= $b['id'] ?>" name="id">
                                        <input type="hidden" value="0" name="is_redeem">
                                        <input type="submit" value="Go" class="button" name="btnsubmit">


                                    <? }
                                } ?>
                            </td>	
                        </form>	
                        <?
                        if ($b['is_redeem'] == 0) {
                            ?>
                            <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm">
                                <td width="50%" valign="middle" align="right">
                                    <?
                                    if ($b['status'] > 1) {
                                        ?>

                                        Resend
                                        <select name="status" style="color:#0066CC;font-size:10px ">
                                            <?
                                            if ($b['status'] == 2) {
                                                ?>
                                                <option value="2">Invoice</option>
                                                <?
                                            } elseif ($b['status'] == 3 || $b['status'] == -4) {
                                                ?>
                                                <option value="2">Invoice</option>
                                                <option value="4">Receipt</option>
                                                <?
                                            } elseif ($b['status'] == 4 || $b['status'] == 5 || $b['status'] == 10) {
                                                ?>
                                                <option value="2">Invoice</option>
                                                <option value="4">Receipt</option>
                                                <option value="5">Courier Info</option>
                                            <? } ?>
                                        </select>
                                        <input type="hidden" value="<?= $b['id'] ?>" name="id">
                                        <input type="hidden" value="0" name="is_redeem">
                                        <input type="submit" value="submit" class="button" name="btnsendemail">

                                    <? } ?>
                                </td>	
                            </form>	
                        <? } ?>
            </tr>

            <tr>

            </tr>

            <tr>
                <td colspan="3">
                    <table  align="center" cellpadding="5" cellspacing="0">
                        <?
                        if ($b['is_redeem'] == 1) {
                            ?>
                            <td align="center" valign="top">
                                <?
                                if ($b['status'] == 0 || $b['status'] == 1) {
                                    ?>
                                    <input type="button" value="Cancel Redemption" class="button" onClick="window.open('order_delete.php?id=<?= $bid ?>','_self')">

                                <? } ?>
                            </td>
                            <?
                        } else {

                            if ($b['status'] < 3) {
                                ?>
                                <td align="center" valign="top">
                                    
                                    <input type="button" value="Delete Order" class="button" onClick="window.open('order_delete.php?id=<?= $bid ?>','_self')">

                                </td>
                                <?
                            } else {
                                if ($b['sale_close'] == 0) {
                                    ?>

                                    <Td align="center" valign="top" >
                                        <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="frm">
                                            <table width="100%" cellpadding="0" cellspacing="0">
                                                <td >
                                                    <input type="submit" value="Close This Sales" name="btnsubmit" class="button">
                                                    <input type="hidden" name="status" value="9">
                                                    <input type="hidden" name="id" value="<?= $b['id'] ?>">

                                                </td>

                                            </table>
                                        </form>
                                    </Td>
                                <? }
                            } ?>
                            <td valign="top">
                                <?
                                if ($b['status'] >= 2) {
                                    ?>
                                    <input type="button" value="Make Payment Record" class="button" onClick="window.open('order_paymentmade.php?id=<?= $bid ?>','_self')">
                                <? }
                            } ?>	
                        </td>
                    </table>
                </td>
            </tr>
        </table>
        <br>
        <?
        if ($b['goods_received_date'] != '0000-00-00') {
            ?>
            <table width="100%" cellpadding="0" cellspacing="0">
                <td width="33%">Received Date</td><td width="60%">: <font color="#0066CC"><?= $b['goods_received_date'] ?></font></td>
                <td width="7%" rowspan="3" align="right">
                </td>

                <tr>
                    <td>Rate for this purchase</td><td>: <img src="images/1x1_orange.gif" width="<?= $orange ?>" height="5" align="middle"><img src="images/1x1_gray.gif" width="<?= $gray ?>" height="5" align="middle"> <?= scoreBar($b['survey_1']) ?></td>
                </tr>
                <tr>
                    <td>Comment for this purchase</td><td>: <?= $b['review'] ?></td>
                </tr>
            </table>
        <? } ?>

        <?
        
        
        if ($b['status'] == "4" || $b['status']=="5") {
            ?>
            <table width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                        <form method="post" action="<?= $_SERVER['PHP_SELF'] ?>" name="frm1"  onSubmit="return formvalidate(this)">
                            <fieldset><legend><strong>Courier Information</strong></legend>
                                <table width="100%">
                                    <?
                                    if ($b['courier_name'] == "" || $b['ref_no'] == "" || $b['eta'] == "") {
                                        ?>
                                        <Tr>
                                            <td colspan="3"> <font class="dw_notice">Please complete the courier info</font></td>
                                        </tr>
                                        <?
                                    }
                                    ?>

                                    <tr>
                                        <td width="20%">Courier name</td><td width="1%">:</td><td width="79%"><input type="text" name="courier_name" maxlength="100" class="text" value="<?= $b['courier_name'] ?>"></td>
                                    </tr>
                                    <tr>
                                        <td width="20%">Reference number</td><td width="1%">:</td><td width="79%"><input type="text" name="ref_no" maxlength="20" class="text" value="<?= $b['ref_no'] ?>"></td>
                                    </tr>
                                    <tr>
                                        <td width="20%">Estimate Time of Arrival</td><td width="1%">:</td><td width="79%"><input type="text" name="eta" maxlength="20" class="text" value="<?= $b['eta'] ?>"> e.g :<?= date("Y-m-d") ?></td>
                                    </tr>
                                    <tr>
                                    <input type="hidden" value="<?= $b['id'] ?>" name="id">

                                    <td width="20%" colspan="3"><input type="submit" value="Update" class="button" name="btnupdate_courier"></td>
                                    </tr>

                                </table>
                            </fieldset>
                        </form>
                        <br>
                    </td>
                </tr>
            </table>
        <? } ?>
        <table width="100%" bgcolor="#CCCCCC" cellpadding="5" cellspacing="1">
            <tr bgcolor="#F3F3F3" align="center">
                <td width="42%">Product</td><td width="13%">Price(<?= $module_currency_code ?>)</td><td width="15%">Product code</td><td width="11%">Quantity</td><td width="15%">Total(<?= $module_currency_code ?>)</td>
            </tr>
            <?
            $total_item = 0;
            $total_piece = 0;
            $total_allprice = 0;
            while ($c = mysql_fetch_array($get_item)) {
                $total_price = 0;
                $get_product = mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=" . $c['item_id']);
                $a = mysql_fetch_array($get_product, MYSQL_ASSOC);
                $total_price = $c['price'] * $c['quantity'];
                $total_allprice = $total_allprice + $total_price;
                ?>
                <tr bgcolor="#FFFFFF" align="center">
                    <td align="left"><a href="product_viewfull.php?id=<?= $c['pid'] ?>"><?= $a['product_name_eng'] ?></a>
                        <br>Product Option : <strong><?= $a['description'] ?></strong></td><td><?= $c['price'] ?></td><td><?= $a['product_code'] ?></td><td><?= $c['quantity'] ?></td>
                    <td align="right"><?= number_format($total_price, 2) ?></td>
                </tr>
                <?
                $get_addon = mysql_query("select * from os_bill_items where addon_for='" . $c['id'] . "'") or die(mysql_error());

                if (mysql_num_rows($get_addon) > 0) {
                    ?>
                    <tr bgcolor="#FFFFFF">
                        <td colspan="6" valign="middle">
                            <strong> Add-on(s)</strong>
                        </td>									
                    </tr>
                    <?
                    while ($addon = mysql_fetch_assoc($get_addon)) {
                        $get_product = mysql_query("select a.product_name_eng,a.product_code,b.description,b.unit_price from os_products a inner join os_product_inventory b on a.id=b.pid where b.id=" . $addon['item_id']);
                        $ap = mysql_fetch_array($get_product, MYSQL_ASSOC);
                        $total_price = $ap['unit_price'] * $addon['quantity'];
                        $total_allprice = $total_allprice + $total_price;
                        ?> 
                        <tr bgcolor="#FFFFFF" align="center">
                            <td align="left"><a href="os_view_full.php?id=<?= $ap['pid'] ?>"><?= $ap['product_name_eng'] ?></a>
                                <br>Product Option : <strong><?= $ap['description'] ?></strong></td><td><?= $ap['unit_price'] ?></td><td><?= $ap['product_code'] ?></td><td><?= $addon['quantity'] ?></td>
                            <td align="right"><?= number_format($total_price, 2) ?></td>
                        </tr>


                        <?
                    }
                }
            }
            ?>
            <tr bgcolor="#FFFFFF">
                <Td colspan="5">
                    <?
                        if($update_allow==1){
                    ?>
                    <input type="submit" value="Modify" class="button" name="btnModifyOrder" onclick="window.open('order_modify_item.php?bid=<?= $bid ?>','_self')" />
                    <? } ?>
                </Td>
            </tr>
        </table>
        <br><br>
    </td>
</tr>

<tr>
    <td>
        <fieldset><legend><strong>Receiver Details</strong></legend>
            <form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
                <table width="100%">
                    <tr>
                        <td width="13%">Name</td><td width="1%">:</td><td width="29%">
                            <input type="text" name="name" value="<?= $b['receiver_name'] ?>" size="30" maxlength="100">
                        </td>
                        <td width="16%">Email</td><td width="1%">:</td><td width="40%">
                            <input type="text" name="email" value="<?= $b['email'] ?>" size="30" maxlength="100">
                        </td>
                    </tr>
                    <tr>
                        <td width="13%">Address</td><td width="1%">:</td><td width="29%">
                            <input type="text" name="address1" value="<?= $b['address1'] ?>" size="30" maxlength="200">
                        </td>
                        <td width="16%">Contact Number</td><td width="1%">:</td><td width="40%">
                            <input type="text" name="contact_number" value="<?= $b['contact_number'] ?>" size="30" maxlength="100">
                        </td>
                    <tr>
                        <td colspan="2"></td><td width="29%">
                            <input type="text" name="address2" value="<?= $b['address2'] ?>" size="30" maxlength="200">

                        </td>
                    </tr>
                    <tr>
                        <td width="13%">Postcode</td><td width="1%">:</td><td width="29%">
                            <input type="text" name="postcode" value="<?= $b['postcode'] ?>" size="30" maxlength="200">
                        </td>
                        <td width="16%">City</td><td width="1%">:</td><td width="40%">
                            <input type="text" name="city" value="<?= $b['city'] ?>" size="30" maxlength="200">

                        </td>
                    </tr>


                    <tr>
                        <td>State</td><td>:</td><td><div id="divState">
                                <?
                                
                                $get_place = mysql_query("select * from os_state where country_id='" . $b['country'] . "' order by name_eng asc")or die(mysql_error());
                                
                                ?>
                                <select name="state" class="text">
                                    <option value="">Please select</option>
                                    <?
                                    while ($s = mysql_fetch_array($get_place, MYSQL_ASSOC)) {
                                        if ($s['id'] == $b['state']) {
                                            $sslt = "selected";
                                        } else {
                                            $sslt = "";
                                        }
                                        ?>
                                        <option <?= $sslt ?> value="<?= $s['id'] ?>"><?= $s['name_eng'] ?></option>
                                        <?
                                    }
                                    ?>
                                </select>
                            </div>
                        </td>
                        <td>Country</td><td>:</td><td>
                            <?
                            $get_place = mysql_query("select * from os_country order by engname asc");
                            ?>
                            <select name="country" class="text" onChange="changeState(this.value)">

                                <?
                                while ($s = mysql_fetch_array($get_place, MYSQL_ASSOC)) {
                                    if ($s['id'] == $b['country']) {
                                        $desslt = "selected";
                                    } else {
                                        $desslt = "";
                                    }
                                    ?>
                                    <option value="<?= $s['id'] ?>" <?= $desslt ?>><?= $s['engname'] ?></option>
                                    <?
                                }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr valign="top">
                        <td>Message</td><td>:</td><td colspan="4">
                            <textarea rows="5" cols="35" name="message" class="text" ><?= $b['message'] ?></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" align="left"> 
                             <?
                        if($update_allow==1){
                    ?>
                            <input type="hidden" value="<?= $b['id'] ?>" name="id">
                            <input type="submit" value="Update" class="button" name="btnupdate_info"> 
                        <? } ?>
                        </td>
                        
                    </tr>

                </table>
            </form>
        </fieldset>	
        <br>
    </td>
</tr>


<tr>
    <td>
        <fieldset><legend><strong>Order Details</strong></legend>
            <table width="100%">
                <tr>
                    <td width="20%">Order Number</td><td width="1%">:</td><td width="79%" ><?= $b['order_request_number'] ?>	</td>
                </tr>
                <?
                if ($b['status'] >= 2) {
                    ?>
                    <tr>
                        <td width="20%">Invoice Number</td><td width="1%">:</td><td width="79%" ><?= $b['invoice_number'] ?>	</td>
                    </tr>
                <? } ?>

                <?
                if ($b['status'] >= 3) {
                    ?>
                    <tr>
                        <td width="20%">Receipt Number</td><td width="1%">:</td><td width="79%" ><?= $b['receipt_number'] ?>	</td>
                    </tr>
                <? } ?>

                <?
                if ($b['status'] >= 5) {
                    ?>
                    <tr>
                        <td width="20%">Courier Number</td><td width="1%">:</td><td width="79%" ><?= $b['courier_number'] ?>	</td>
                    </tr>
                <? } ?>
                <form method="post" action="<?= $_SERVER['PHP_SELF'] ?>" name="frm">
                    <tr>
                        <td >Order Date</td><td width="1%">:</td><td ><?= $b['create_date'] ?></td>


                    </tr>
                    <tr>
                        <td >Service Preferred</td><td width="1%">:</td><td ><?= getDataById("os_shipping_company", "company_name", "id", $b['service_preferred']) ?></td>

                    </tr>
                    <?
                    $total_amount = $b['total_amount'];
                    $discount = ($b['discount'] / 100) * $total_amount;
                    $final_amount = ($total_amount - $discount) + $b['transport_fees'];
                    ?>

                    <tr>
                        <td >Total Product Amount(<?= $module_currency_code ?>)</td><td width="1%">:</td><td ><?= number_format($b['total_amount'], 2) ?></td>
                    </tr>

                    <tr>
                        <td >Discount</td><td width="1%">:</td><td ><input type="text" value="<?= $b['discount'] ?>" name="discount" size="2" class="text" maxlength="2">%</td>
                    </tr>
                    <Tr>
                        <td >Transport Fees</td><td width="1%">:</td><td ><input type="text" value="<?= $b['transport_fees'] ?>" name="transport_fees" size="5" class="text" maxlength="5"></td>
                    </Tr>
                    <tr>
                        <td >Total Overall Amount</td><td width="1%">:</td><td ><?= number_format($final_amount, 2) ?></td>
                    </tr>
                    <tr>
                    <input type="hidden" value="<?= $b['id'] ?>" name="id">
                    <td  colspan="8">
                        <?
                        if($update_allow==1){
                    ?>
                        <input type="submit" value="Update" class="button" name="btnupdate">
                    <? } ?>
                    </td>
                    </tr>

                </form>
            </table>
        </fieldset>
        <br><br>
    </td>
</tr>







<?
if ($b['cc_status'] == 1) {
    $get_cc = mysql_query("select * from os_ccrecord where bill_id=$bid");

    if (mysql_num_rows($get_cc) > 0) {
        $cc = mysql_fetch_array($get_cc, MYSQL_ASSOC);
        ?>
        <tr>
            <Td colspan="5"><br>
                <table width="100%">
                    <td colspan="6"><b>Credit Card Payment record</b></td>
                    <tr>
                        <td width="20%">Transaction Id</td><td width="1%">:</td><td width="79%"><?= $cc['tran_id'] ?></td>
                    </tr>
                    <tr>
                        <td>Approval Code</td><td>:</td><td><?= $cc['app_code'] ?></td>
                    </tr>
                    <tr>
                        <td>Amount Paid</td><td>:</td><td><?= $cc['currency'] ?> <?= $cc['bill_amount'] ?></td>
                    </tr>
                    <tr>
                        <td>Transaction Date &amp; Time</td><td>:</td><Td><?= $cc['payment_date'] ?></Td>
                    </tr>
                </table>

            </Td>

        </tr>


    <? }
} ?>


<?
$get_payment = mysql_query("select * from os_payment_record where bid='$bid' order by create_datetime asc");
if (mysql_num_rows($get_payment) > 0) {
    ?>
    <tr>
        <td>
            <table width="100%" cellpadding="0" cellspacing="0" class="solidborder">
                <?
                $no = 1;
                while ($p = mysql_fetch_array($get_payment)) {
                    ?>
                    <tr>
                        <td width="100%">
                            <table width="100%">
                                <td width="13%" colspan="6" bgcolor="#F3F3F3"><b>Payment record <?= $no ?></b></td>
                                <tr>
                                    <td>Payment date</td><td width="1%">:</td><td width="29%"><?= $p['paymentdate'] ?></td>
                                    <td width="16%">Payment amount</td><td width="1%">:</td><td width="40%"><?= $module_currency_code ?> <?= number_format($p['paidamount'], 2) ?></td>
                                </tr>
                                <?
                                if ($p['is_paypal'] == 0) {
                                    ?>
                                    <tr>
                                        <td>Payment bank</td><td>:</td><td><?= $p['paymentbank'] ?></td>
                                        <td>Account number</td><td>:</td><td><?= $p['accountnumber'] ?></td>
                                    </tr>

                                    <?
                                } else {
                                    ?>
                                    <tr>
                                        <td>Payment bank</td><td>:</td><td>Paypal</td>
                                        <td>Paypal transaction ID</td><td>:</td><td><?= $p['txn_id'] ?></td>
                                    </tr>
                                    <tr>
                                        <td>Payer transaction ID</td><td>:</td><td><?= $p['payer_id'] ?></td>
                                    </tr>
                                <? } ?>

                                <tr>
                                    <td >Remark</td><td>:</td ><td colspan="4">

                                        <?= $p['message'] ?></td>
                                </tr>
                                <tr>

                                </tr>
                            </table>

                        </td>

                    </tr>
                    <? $no++;
                } ?>
            </table>
        </td>
    </tr>

<? } ?>		  
</table>


</Td>  
</table>

<? require("required/footer.php"); ?>	